package com.battery.controller;

import com.battery.pojo.Sys_User;
import com.battery.service.Sys_UserService;
import com.battery.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "系统用户管理相关接口")
public class Sys_UserController {
    @Autowired
    Sys_UserService sys_UserService;

    @PostMapping("/sys_User")
    @ResponseBody
    @ApiOperation("列出所有系统用户")
    public Result showsys_User(){

        Result result = sys_UserService.queryAllSys_User();
        return Result.ok().data("data",result);

    }

    @PostMapping( "/addsys_User")
    @ResponseBody
    @ApiOperation("增加系统用户")
    public Result addsys_User(@RequestBody @ApiParam(name="系统用户对象",value="传入json格式",required=true) Sys_User sys_User){

        Result result = sys_UserService.addSys_User(sys_User);
        System.out.println(sys_User.getSys_user_name());
        return Result.ok().data("data",result);

    }

    @DeleteMapping("/deletesys_User/{sys_user_name}")
    @ResponseBody
    @ApiOperation("删除系统用户")
    public Result deletesys_User(@PathVariable("sys_user_name") @ApiParam(name="系统用户id",required=true) String sys_user_name){

        Result result = sys_UserService.dropSys_User(sys_user_name);
        return Result.ok().data("data",result);

    }

    @GetMapping("/querysys_User/{sys_user_name}")
    @ResponseBody
    @ApiOperation("查询系统用户")
    public Result querysys_User(@PathVariable("sys_user_name") @ApiParam(name="系统用户id",required=true) String sys_user_name){

        Result result = sys_UserService.querySys_User(sys_user_name);
        return Result.ok().data("data",result);

    }

    @PutMapping("/modifysys_User")
    @ResponseBody
    @ApiOperation("修改系统用户")
    public Result modifysys_User(@RequestBody @ApiParam(name="系统用户对象",value="传入json格式",required=true) Sys_User sys_User){

        Result result = sys_UserService.modifySys_User(sys_User);
        return Result.ok().data("data",result);

    }
}
